* Construct imported input shares at the country level from OECD
clear
set more off
local countries "AUS AUT BEL CAN CHL CZE DNK EST FIN FRA DEU GRC HUN ISL IRL ISR ITA JPN LUX NLD NZL NOR POL PRT SVK SVN ESP SWE CHE GBR USA BGR BRN CHN CRI CYP HKG HRV IND KHM LTU LVA MLT PHL ROU SAU SGP TUN TWN VNM ZAF RoW BRA RUS IDN KOR TUR MYS ARG COL MEX THA"
foreach cc of local countries {
foreach t of numlist 1995(1)2011 {
import delimited using "OECD/input/`cc'`t'domimp", clear
drop cons gfcf invnt cons_nonres cons_abr expo gdp
gen var = _n
drop if var>68
gen dom = 0
replace dom =1 if var<=34
gen imp = 0
replace imp =1 if var>=35 
egen totalpurch = rowtotal(c01t05-c95)
gen totalpurch_dom_temp = totalpurch * dom
gen totalpurch_imp_temp = totalpurch * imp
egen totalDOM = total(totalpurch_dom_temp)
egen totalIMP = total(totalpurch_imp_temp)
gen total = totalDOM + totalIMP
gen importshare = totalIMP / total
keep if var==1
keep importshare
gen year=`t'
gen Country="`cc'"
save "OECD/temp/`cc'`t'.dta", replace
}
use "OECD/temp/`cc'1995.dta"
foreach t of numlist 1996(1)2011 {
append using "OECD/temp/`cc'`t'.dta"
}
save "OECD/temp/`cc'_append.dta", replace
}
local countries2 "AUS AUT BEL CAN CHL CZE DNK EST FIN FRA DEU GRC HUN ISL IRL ISR ITA JPN LUX NLD NZL NOR POL PRT SVK SVN ESP SWE CHE GBR USA BGR BRN CHN CRI CYP HKG HRV IND KHM LTU LVA MLT PHL ROU SAU SGP TUN TWN VNM ZAF RoW BRA RUS IDN KOR TUR MYS ARG COL MEX"
foreach cc of local countries2 {
append using "OECD/temp/`cc'_append.dta"
}
save "OECD/output/IMPORTSHARES_OECD_inputs_allcountries.dta", replace

